﻿using System;
using System.Threading.Tasks;
using JT.WEB.Models.Were;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;

namespace JT.WEB.Controllers
{
    public class NameClassController : Controller
    {
        private readonly ContextWere _context;

        public NameClassController(ContextWere dBChuRuInfo5Context)
        {
            _context = dBChuRuInfo5Context;
        }
        // GET: NameClass
        public async Task<ActionResult> Index()
        {
            System.Collections.Generic.List<TbNameClass> nameClass = await _context.TbNameClass.ToListAsync();
            return View(nameClass);
        }

        // GET: NameClass/Details/5
        public async Task<ActionResult> Details(string NameClass)
        {
            TbNameClass nameClass = await _context.TbNameClass.FindAsync(NameClass);
            return View(nameClass);
        }

        // GET: NameClass/Create
        public ActionResult Create()
        {
            return View();
        }

        // POST: NameClass/Create
        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Create([Bind("NameClass")]TbNameClass InameClass)
        {
            if (ModelState.IsValid)
            {
                _context.Add(InameClass);
                await _context.SaveChangesAsync();
                return RedirectToAction(nameof(Index));
            }
            return View(InameClass);
        }

        // GET: NameClass/Edit/5
        public async Task<ActionResult> Edit(string NameClass)
        {
            if (String.IsNullOrEmpty(NameClass))
            {
                return NotFound();
            }
            TbNameClass nameClass = await _context.TbNameClass.FindAsync(NameClass);
            return View(nameClass);
        }

        // POST: NameClass/Edit/5
        [HttpPost]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> Edit(int id, [Bind("NameClass")]TbNameClass InameClass)
        {

            if (ModelState.IsValid)
            {
                _context.Update(InameClass);
                await _context.SaveChangesAsync();
                return RedirectToAction(nameof(Index));

            }
            return View(InameClass);


        }

        // GET: NameClass/Delete/5
        public async Task<ActionResult> Delete(string NameClass)
        {
            if (String.IsNullOrEmpty(NameClass))
            {
                return NotFound();
            }
            TbNameClass nameClass = await _context.TbNameClass.FindAsync(NameClass);
            return View(nameClass);
        }

        // POST: NameClass/Delete/5
        [HttpPost, ActionName("Delete")]
        [ValidateAntiForgeryToken]
        public async Task<ActionResult> DeleteConFirmed(string id)
        {
            if (ModelState.IsValid)
            {
                TbNameClass InameClass = await _context.TbNameClass.FindAsync(id);
                _context.Remove(InameClass);
                await _context.SaveChangesAsync();
                return RedirectToAction(nameof(Index));
            }
            return View(id);
        }
    }
}